package io.shqyang.done.slice.main.provider;

import io.shqyang.done.ResourceTable;
import io.shqyang.done.slice.main.quick.QuickProvider;
import io.shqyang.done.slice.main.model.Done;
import ohos.aafwk.ability.AbilitySlice;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.utils.Color;

import java.util.List;

public class DoneProvider extends QuickProvider<Done> {

    public DoneProvider(AbilitySlice slice, List<Done> data) {
        super(slice, data, ResourceTable.Layout_item_done);
    }

    @Override
    protected void onBindComponent(Component component, int position) {
        Done done = getItem(position);
        System.out.println("是啊啊：有：" + done.getTitle());
        bindText(component, ResourceTable.Id_title_tt, done.getTitle());
        Button button = (Button) component.findComponentById(ResourceTable.Id_done_btn);
        if (done.isDone()) {
            button.setWidth(150);
            button.setTextColor(Color.DKGRAY);
            button.setBackground(null);
            button.setText("已完成");
        } else {
            button.setText("√");
            button.setClickedListener(v->{
                done.setDone(true);
                notifyDataChanged();
            });
        }
    }

}
